package com.example.springLearning.part9.controller;

import com.example.springLearning.part9.config.MyLifeCycle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/spring/part9")
public class Spring9Controller {

    @Autowired
    private AbstractApplicationContext context;

    @Autowired
    MyLifeCycle lifeCycle;

    @RequestMapping(path = "publishEvent", method = RequestMethod.GET)
    public String notifyEvent() {
        context.start();
        return "ok";
    }

    @RequestMapping(path = "publishEvent1", method = RequestMethod.GET)
    public String notifyEven1t() {
        lifeCycle.start();
        return "ok";
    }
}
